﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Microsoft.Xna.Framework;

namespace TetrisConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var tetris = new Tetris(12,22);
            tetris.TimerTick(null);
        }
    }

    class Tetris
    {
        int[][] _block;
        int _cols;
        int _rows;
        System.Threading.Timer _timer;

        public Tetris(int cols, int rows)
        {
            _cols = cols;
            _rows = rows;
            _block = GetNewWall(cols, rows);
            _block[0][0] = 1;
            _block[0][1] = 1;
            _block[1][0] = 1;
            _block[1][1] = 1;

            //_timer = new System.Threading.Timer(TimerTick);
            //_timer.Change(0, 1000);
        }

        ~Tetris()
        {
            //_timer.Dispose();
        }

        public void TimerTick(object state)
        {
            ShiftBlock();
        }

        private int[][] GetNewWall(int cols, int rows)
        {
            var block = new int[cols][];

            for (int i = 0; i < cols; i++)
            {
                block[i] = new int[rows];
            }

            return block;
        }

        private int[][] ShiftBlock()
        {
            var block = GetNewWall(_cols, _rows);

            for (int i = 0; i < _cols - 1; i++)
            {
                block[i] = DoShift(1, _block[i]);
            }

            return block;
        }

        private int[] DoShift(int shift, int[] sourceArray)
        {
            int offset = shift % sourceArray.Length;
            int[] targetArray = new int[_rows];

            Buffer.BlockCopy(sourceArray, 0, targetArray, offset * sizeof(int), (sourceArray.Length - offset) * sizeof(int));

            return targetArray;
        }
    }
}
